#!/bin/bash

string_1='                  '
string_2='---------------------------'
green='\e[32m'
red='\e[31m'
defult='\e[39m'
blue='\e[34m'
end='\e[0m'

red_ball=""
bule_ball=""

echo -e "$green$string_2 机选双色球 $string_2\n"
echo -en "$green 正在为您生成红色球，请稍候..."

while :
do
    tmp=$[RANDOM%33+1]
    #红球中已存在生成的随机数则跳过该次重新生成
    echo "$red_ball" | grep -q -w $tmp && continue
    red_ball+=" $tmp"
    num=`echo $red_ball | wc -w`
    echo -en " $num"
    if [ $num -eq 6 ];then
        echo -e "$green\n 正在为您生成蓝色球，请稍候... 1"
        bule_ball=$[RANDOM%16+1]
        sleep 0.5
        break
    fi
    sleep 0.5
done

if [[ -z $red_ball || -z $bule_ball ]];then
    echo -e "$red 生成失败，请重新运行脚本\n"
    exit
else
    echo -e "$green\n 已为您生成双色球，号码如下：\n"
    echo -e "$red $red_ball $blue $bule_ball"
fi
